#include "game.hh"
#include <fstream>
#include <iostream>
#include <vector>

int getImpossibleIDSum(const std::vector<Game>& games)
{
    // Red: 12, Green: 13, Blue: 14
    int sum{0};
    for ( const Game& game : games )
    {
        bool suitable{true};
        for (const CubesSize& size : game.sets())
        {
            if (size.red > 12 || size.green > 13 || size.blue > 14)
            {
                suitable = false;
                break;
            } 
        }
        if (suitable)
            sum += game.id();
    }

    return sum;
}

int getPowerSum(const std::vector<Game>& games)
{
    int sum{0};
    for ( const Game& game : games )
    {
        int maxRed{-1}, maxGreen{-1}, maxBlue{-1};
        for (const CubesSize& size : game.sets())
        {
            if (size.red > maxRed) maxRed = size.red;
            if (size.green > maxGreen) maxGreen = size.green;
            if (size.blue > maxBlue) maxBlue = size.blue;
        }
        int power{ maxRed * maxGreen * maxBlue };
        sum += power;
    }

    return sum;
}

int main() 
{
    std::ifstream file{ "./src/day02/input.txt" };
    std::string line;
    std::vector<Game> games;

    while ( std::getline(file, line) )
        games.emplace_back( line );

    // std::cout << getImpossibleIDSum(games) << std::endl;
    std::cout << getPowerSum(games) << std::endl;

    return 0;
}